#!/usr/bin/env python
# coding: utf-8

# In[ ]:


students_grades = {}
def add_grade():
    pass
def query_grade():
   
    pass
def statistics_grade():
    
    pass

def main_menu():
   
    while True:
        print("1. 添加学生成绩")
        print("2. 查询学生成绩")
        print("3. 统计学生成绩")
        print("4. 退出")
        choice = input("请输入你的选择: ")
        if choice == "1":
            add_grade()
        elif choice == "2":
            query_grade()
        elif choice == "3":
            statistics_grade()
        elif choice == "4":
            print("退出系统")
            break
        else:
            print("无效选择，请重新输入")



def add_grade():
    student_id = input("请输入学生学号: ")
    student_name = input("请输入学生姓名: ")
    course_name = input("请输入课程名称: ")
    grade = input("请输入成绩: ")
    if student_id not in students_grades:
        students_grades[student_id] = {
            "name": student_name,
            "grades": {}
        }
    students_grades[student_id]["grades"][course_name] = grade
    print("成绩添加成功")





def query_grade():
    student_id = input("请输入要查询的学生学号: ")
    if student_id in students_grades:
        print(f"学生姓名: {students_grades[student_id]['name']}")
        for course, grade in students_grades[student_id]['grades'].items():
            print(f"课程: {course}, 成绩: {grade}")
    else:
        print("未找到该学生信息")





def statistics_grade():
    if not students_grades:
        print("没有成绩数据可供统计")
        return
    total_grades = 0
    count = 0
    for student in students_grades.values():
        for grade in student['grades'].values():
            total_grades += float(grade)
            count += 1
    average_grade = total_grades / count if count > 0 else 0

    print(f"所有学生的平均成绩: {average_grade}")





if __name__ == "__main__":
    main_menu()


# In[ ]:




